package cn.yunbamboos.media.zlm;

import cn.yunbamboos.media.zlm.client.ZLMClient;

import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

public class ZLMClientList {


    /**
     * key : mediaServerId
     */
    private final Map<String, ZLMClient> clients = new ConcurrentHashMap<>();

    private final String localMediaServerId;
    private final ZLMClient localClient;

    public ZLMClientList(String localMediaServerId, ZLMClient localClient) {
        this.localMediaServerId = localMediaServerId;
        this.localClient = localClient;
    }

    public ZLMClient getLocalZLMClient(){
        return localClient;
    }

    public Optional<ZLMClient> get(String mediaServerId) {
        if (!localMediaServerId.equals(mediaServerId)) {
            return Optional.ofNullable(clients.get(mediaServerId));
        }
        return Optional.of(localClient);
    }
}
